package laboratoryQ;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JLabel;

import laboratoryQ.experiment.IExperiment;
import laboratoryQ.experiment.IExperimentResult;
import laboratoryQ.experiment.IExperiment.IExpRunStatusHandler;
import laboratoryQ.experiment.settings.BaseExperimentSettings;
import laboratoryQ.experiment.settings.IExperimentSettings;
import laboratoryQ.experiment.settings.SettingsAnnotations.Increase;
import laboratoryQ.experiment.ui.reportage.ExperimentReportage;
import laboratoryQ.experiment.ui.reportage.IExperimentResult2componentConverter;
import laboratoryQ.experiment.ui.reportage.IReportageModel;

public class MainLQExample implements IReportageModel {
	static { System.out.println("\nSMALL POST_PORTING move 2 examples"); }

	public static void main(String[] args) {
		new MainLQExample().showReportagePureModel();
		showReportageSettingsBasedModel();
	}
	
	public static class ExampleSett extends BaseExperimentSettings {
		@Increase(value = 5, boundBegin = 0, boundEnd = Integer.MAX_VALUE)
		public int sett0 = -1;
		@Increase(value = 0.5, boundBegin = 0, boundEnd = Integer.MAX_VALUE)
		public double sett1 = -1.0;
	}
	
	public static class ExampleER2DConv implements IExperimentResult2componentConverter {
		@Override
		public List<JComponent> convert2component(
				IExperimentResult expResult
		) {
			List<JComponent> list = new ArrayList<JComponent>();
			list.add(new JLabel("0"));
			list.add(new JLabel("1"));
			list.add(new JLabel("2"));
			return list;
		}
		@Override
		public String getViewTitleAt(int position) {
			return "Title " + position;
		}
		@Override
		public String getExperimentTitle() {
			return "Exp title";
		}
		@Override
		public void onExperimentRunStart(List<JComponent> viewComponents) {
		}
	}
	
	public static class ExampleExperiment implements IExperiment {
		@Override
		public IExperimentResult runExperiment(
				IExperimentSettings settings,
				IExpRunStatusHandler expRunStatusHandler
		) {
			expRunStatusHandler.handleExperimentResult(null);
			return null;
		}
	}
	
	private static void showReportageSettingsBasedModel() {
		ExampleSett settings = new ExampleSett();
		settings.initialise();
		settings.sett0 = 1;
		settings.sett1 = 1.0;
		settings.experiment = new ExampleExperiment();
		settings.validate();
		
		IExperimentResult2componentConverter er2dConv = new ExampleER2DConv();
		
		ExperimentReportage experimentReportage = 
			ExperimentReportage.newExperiment2componentReportage(
					settings, 
					er2dConv
			);
		experimentReportage.showReportageFrame();
	}

	public void showReportagePureModel() {
		ExperimentReportage experimentReportage = new ExperimentReportage(this);
		experimentReportage.initialise();
		experimentReportage.showReportageFrame();
	}

	@Override
	public String getExperimentTitle() {
		return "LQEx";
	}

	@Override
	public JComponent getSetupSettingsComponent() {
		return new JLabel("Settings");
	}

	@Override
	public JComponent getViewComponentAt(int i) {
		return new JLabel("VC" + i);
	}

	@Override
	public String getViewTitleAt(int i) {
		return "Title " + i;
	}

	@Override
	public int getViewsCount() {
		return 5;
	}

	@Override
	public void shutdown() {
	}

	@Override
	public IExpRunStatusHandler getExperimentResultHandler() {
		return null;
	}

	@Override
	public IExperimentSettings getSettings() {
		return null;
	}

	@Override
	public void onExperimentRunStart() {
	}
}
